package com.itydl.a04;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.itydl.a04.view.ParallaxListView;

public class MainActivity extends AppCompatActivity {

    private ParallaxListView mListView;
    private View mHeadView;
    private ImageView mIvHead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView = (ParallaxListView) findViewById(R.id.lv);
        mHeadView = View.inflate(this, R.layout.layout_head,null);
        mIvHead = (ImageView) mHeadView.findViewById(R.id.iv);
        mListView.addHeaderView(mHeadView);

        mIvHead.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                mListView.setHeadImageView(mIvHead);
                mIvHead.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

        mListView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Strings.NAMES));
    }
}
